package com.toy.core.util;

import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public class ScheduledThreadPool {
	
	private static ScheduledExecutorService executorService =  Executors.newScheduledThreadPool(20);
	
	public static Future<?> submit(Runnable task){
		return executorService.submit(task);
	}
	/**
	 * @command the task to execute
	 * @initialDelay the time to delay first execution
	 * @period the period between successive executions
	 * @unit the time unit of the initialDelay and period parameters
	 */
	public static ScheduledFuture<?>  scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit){
		return executorService.scheduleAtFixedRate(command, initialDelay, period, unit);
	}
		
}
